<?php
class IndexUpdateAction extends AdminAction
{
	public function __construct()
	{
		parent::__construct();
		$this->responseType = 'json';
	}
	
	public function execute()
	{
		$id				= $this->context->post('id');
		if(is_numeric($id) && $id)
		{
			$moduleService		= new ModuleService();
			$data				= $moduleService->get($id);
			$productService		= new ProductService();
			$con				= $data['info']['con'];
			$con['page_no']		= 1;
			if(!array_key_exists('page_size',$con) || !is_numeric($con['page_size']) || $con['page_size']<0 || $con['page_size']>40)
			{
				$con['page_size']	= 20;
			}
			$cols				= array('iid','num_iid','title','nick','pic_url','price','click_url');
			$productService->searchTaoKeProducts($con,$cols,false);
			$productList		= $productService->getProductList();
			if($productList)
			{
				foreach($productList as &$plv)
				{
					$plv['title']	= strip_tags($plv['title']);
				}
				//更新数据
				$moduleService->update($id,array('data'=>$productList));
				$this->code	= 200;
			}
			else
			{
				$this->code	= 400;
			}
		}
		else
		{
			$this->code	= 400;
		}
	}
}
